package com.only4play.practice.common.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.only4play.codegen.support.constants.BaseEnum;

import java.util.Optional;

/**
 * @author mengdy
 */

public enum OrderState implements BaseEnum<OrderState> {

  /**
   *
   */
  CREATED(1,"订单已创建"),
  WAITING(2, "交易待完成"),
  SUCCESS(3,"交易完成"),
  TIME_OUT_ABANDON(4,"交易超时取消"),
  CANCEL(5,"交易已取消"),

  FAILED(-1,"交易失败"),

  ;

  OrderState(Integer code, String name) {
    this.code = code;
    this.name = name;
  }
  @EnumValue
  private Integer code;
  private String name;

  @Override
  public Integer getCode() {
    return this.code;
  }

  @Override
  public String getName() {
    return this.name;
  }

  public static Optional<OrderState> of(Integer code) {
    return Optional.ofNullable(BaseEnum.parseByCode(OrderState.class, code));
  }

}
